<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-hemisu.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-hemisu.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-hemisu.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="hemisu">










<meta name="description" content="Just do...">
<meta name="keywords" content="web, 前端, 生活, 分享">
<meta property="og:type" content="website">
<meta property="og:title" content="何米酥`s Blog">
<meta property="og:url" content="http://www.hemisu.com/page/18/index.html">
<meta property="og:site_name" content="何米酥`s Blog">
<meta property="og:description" content="Just do...">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="何米酥`s Blog">
<meta name="twitter:description" content="Just do...">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://www.hemisu.com/page/18/">





  <title>何米酥`s Blog</title>
  








  <!-- Hotjar Tracking Code for www.hemisu.com -->
  <script>
      (function(h,o,t,j,a,r){
          h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
          h._hjSettings={hjid:1933736,hjsv:6};
          a=o.getElementsByTagName('head')[0];
          r=o.createElement('script');r.async=1;
          r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
          a.appendChild(r);
      })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
  </script>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">何米酥`s Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">EFE</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/01/73/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/01/73/" itemprop="url">PAT B1028</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-01T23:31:00+00:00">
                2017-02-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>某城镇进行人口普查，得到了全体居民的生日。现请你写个程序，找出镇上最年长和最年轻的人。</p>
<p>这里确保每个输入的日期都是合法的，但不一定是合理的——假设已知镇上没有超过200岁的老人，而今天是2014年9月6日，所以超过200岁的生日和未出生的生日都是不合理的，应该被过滤掉。</p>
<p>输入格式：</p>
<p>输入在第一行给出正整数N，取值在(0, 105]；随后N行，每行给出1个人的姓名（由不超过5个英文字母组成的字符串）、以及按“yyyy/mm/dd”（即年/月/日）格式给出的生日。题目保证最年长和最年轻的人没有并列。</p>
<p>输出格式：</p>
<p>在一行中顺序输出有效生日的个数、最年长人和最年轻人的姓名，其间以空格分隔。</p>
<p>输入样例：<br>5<br>John 2001/05/12<br>Tom 1814/09/06<br>Ann 2121/01/30<br>James 1814/09/05<br>Steve 1967/11/20<br>输出样例：<br>3 Tom John</p>
<p>算法笔记代码：</p>
<pre><code>#include &quot;stdio.h&quot;
   //#include &quot;algorithm&quot;
   //using namespace std;
   struct person{
       char name[10];
       int year, month, day;
   } oldest, youngest, left, right;
   bool LessEqu(person a, person b){
       if (a.year != b.year) {
           return a.year &lt;= b.year;
       }else if (a.month != b.month){
           return a.month &lt;= b.month;
       }else{
           return a.day &lt;= b.day;
       }
   }
   bool MoreEqu(person a, person b){
       if (a.year != b.year) {
           return a.year &gt;= b.year;
       }else if (a.month != b.month){
           return a.month &gt;= b.month;
       }else{
           return a.day &gt;= b.day;
       }
   }
   void init(){
       youngest.year = left.year = 1814;
       oldest.year = right.year = 2014;
       youngest.month = oldest.month = left.month = right.month = 9;
       youngest.day = oldest.day = left.day = right.day = 6;
   }
   int main(){
       init();
       int n,num;
       person temp;
       scanf(&quot;%d&quot;, &amp;n);
       for (int i = 0; i &lt; n; i++) {
           scanf(&quot;%s %d/%d/%d&quot;, temp.name, &amp;temp.year, &amp;temp.month, &amp;temp.day);
           if (MoreEqu(temp, left) &amp;&amp; LessEqu(temp, right)) {
               num++;
               if (LessEqu(temp, oldest)) {
                   oldest = temp;
               }
               if (MoreEqu(temp, youngest)) {
                   youngest = temp;
               }
           }
       }
       if (num == 0) {
           printf(&quot;0\n&quot;);
       }else
       {
           printf(&quot;%d %s %s&quot;, num, oldest.name, youngest.name);
       }
       return 0;
   }
</code></pre><p>收获：<br>有可能存在所有人的日期都不在合法的区间内的情况，这是必须特判输出0，否则会因为后面输出多的空格而返回格式错误。<br>在使用新读入的日期来更新最大日期和最小日期时，有可能同时更新最大日期和最小日期，因此不能使用if……else的写法来选择一个更新。<br>日期比较函数只写一个的写法会导致边界日期处理出现问题。</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/02/01/71/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/02/01/71/" itemprop="url">PAT B1041</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-02-01T22:29:08+00:00">
                2017-02-01
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>每个PAT考生在参加考试时都会被分配两个座位号，一个是试机座位，一个是考试座位。正常情况下，考生在入场时先得到试机座位号码，入座进入试机状态后，系统会显示该考生的考试座位号码，考试时考生需要换到考试座位就座。但有些考生迟到了，试机已经结束，他们只能拿着领到的试机座位号码求助于你，从后台查出他们的考试座位号码。</p>
<p>输入格式：</p>
<p>输入第一行给出一个正整数N（&lt;=1000），随后N行，每行给出一个考生的信息：“准考证号 试机座位号 考试座位号”。其中准考证号由14位数字组成，座位从1到N编号。输入保证每个人的准考证号都不同，并且任何时候都不会把两个人分配到同一个座位上。</p>
<p>考生信息之后，给出一个正整数M（&lt;=N），随后一行中给出M个待查询的试机座位号码，以空格分隔。</p>
<p>输出格式：</p>
<p>对应每个需要查询的试机座位号码，在一行中输出对应考生的准考证号和考试座位号码，中间用1个空格分隔。</p>
<p>输入样例：<br>4<br>10120150912233 2 4<br>10120150912119 4 1<br>10120150912126 1 3<br>10120150912002 3 2<br>2<br>3 4<br>输出样例：<br>10120150912002 2<br>10120150912119 1</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
struct{
    long long testid;
    int sj;
    int ks;
}stu[1010];
int main(){
    int n,search;
    scanf(&quot;%d&quot;, &amp;n);
    for (int i = 0; i &lt; n; i++) {
        scanf(&quot;%lld%d%d&quot;, &amp;stu[i].testid, &amp;stu[i].sj, &amp;stu[i].ks);
    }
//    for (int i = 0; i &lt; n; i++) {
//        printf(&quot;%lld %d %d\n&quot;, stu[i].testid, stu[i].sj, stu[i].ks);
//    }
    scanf(&quot;%d&quot;, &amp;search);
    while (search--) {
        int sj;
        scanf(&quot;%d&quot;, &amp;sj);
        for (int i = 0; i &lt; n; i++) {
            if (sj == stu[i].sj) {
                printf(&quot;%lld %d\n&quot;,stu[i].testid, stu[i].ks);
            }
        }
    }
    return 0;
}
</code></pre><p>算法笔记代码：</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
struct{
    long long testid;
    int ks;
}stu[1010];
int main(){
    int n,search;
    scanf(&quot;%d&quot;, &amp;n);
    for (int i = 0; i &lt; n; i++) {
        long long testid;
        int sj;
        int ks;
        scanf(&quot;%lld%d%d&quot;, &amp;testid, &amp;sj, &amp;ks);
        stu[sj].testid = testid;
        stu[sj].ks = ks;
    }
//    for (int i = 0; i &lt; n; i++) {
//        printf(&quot;%lld %d %d\n&quot;, stu[i].testid, stu[i].sj, stu[i].ks);
//    }
    scanf(&quot;%d&quot;, &amp;search);
    while (search--) {
        int sj;
        scanf(&quot;%d&quot;, &amp;sj);
        printf(&quot;%lld %d\n&quot;,stu[sj].testid, stu[sj].ks);
    }
    return 0;
}
</code></pre><p>收获：<br>需要试机座位号来查询考生且座位号不会重复，所以可以用把试机座位号作为数组的下标，避免查找的时候轮询节省时间。<br>注意点：<br>准考证号14位数字，可以用longlong来存放。<br>int -2<em>10^9~2</em>10^9<br>longlong -9<em>10^18~9</em>10^18</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/26/70/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/26/70/" itemprop="url">PAT A1002</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-26T22:08:36+00:00">
                2017-01-26
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>This time, you are supposed to find A+B where A and B are two polynomials.</p>
<p>Input</p>
<p>Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 … NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, …, K) are the exponents and coefficients, respectively. It is given that 1 &lt;= K &lt;= 10，0 &lt;= NK &lt; … &lt; N2 &lt; N1 &lt;=1000.</p>
<p>Output</p>
<p>For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.</p>
<p>Sample Input<br>2 1 2.4 0 3.2<br>2 2 1.5 1 0.5<br>Sample Output<br>3 2 1.5 1 2.9 0 3.2</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
int main(){
    double a[1010] = {0};
    int k;
    double n;//n为系数
    int e, count = 0;//e为指数，count计数不为零的导数项个数
    scanf(&quot;%d&quot;, &amp;k);
    while (k--) {
        scanf(&quot;%d%lf&quot;, &amp;e, &amp;n);
        a[e] += n;
    }
    scanf(&quot;%d&quot;, &amp;k);
    while (k--) {
        scanf(&quot;%d%lf&quot;, &amp;e, &amp;n);
        a[e] += n;
    }
    for (int i = 0; i &lt;= 1000; i++) {
        if (a[i] != 0) {
            count ++;
        }
    }
    printf(&quot;%d&quot;, count);
    for (int i = 1000; i &gt;= 0; i--) {
        if(a[i] != 0) printf(&quot; %d %.1lf&quot;, i, a[i]);
    }
    return 0;
}
</code></pre><p>收获：<br>此题与PAT B1010一元多项式求导对比：<br>B1010题需要考虑零次项的求导，且得从低次枚举到高次；<br>此题需要考虑用count计数，需要在相加之后（考虑正负相加）计数；</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/26/69/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/26/69/" itemprop="url">PAT B1010</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-26T11:39:00+00:00">
                2017-01-26
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>设计函数求一元多项式的导数。（注：x^n（n为整数）的一阶导数为n*x^n-1。）</p>
<p>输入格式：以指数递降方式输入多项式非零项系数和指数（绝对值均为不超过1000的整数）。数字间以空格分隔。</p>
<p>输出格式：以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔，但结尾不能有多余空格。注意“零多项式”的指数和系数都是0，但是表示为“0 0”。</p>
<p>输入样例：<br>3 4 -5 2 6 1 -2 0<br>输出样例：<br>12 3 -10 1 6 0</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
int main(){
    int a[1010] = {0};
    int k, e, count = 0;//k为系数，e为指数，count计数不为零的导数项个数
    while (scanf(&quot;%d%d&quot;, &amp;k, &amp;e) != EOF) {
        a[e] = k;
    }
    a[0] = 0;
    for (int i = 1; i &lt;= 1000; i++) {
        a[i - 1] = a[i] * i; //求导公式
        a[i] = 0;
        if (a[i -1] != 0) {
            count ++;
        }
    }
    if (count == 0) {
        printf(&quot;0 0&quot;);//特例
    }else{
        for (int i = 1000; i &gt;= 0; i--) {
            if (a[i] != 0) {
                printf(&quot;%d %d&quot;, a[i], i);
                count--;
                if(count !=0) printf(&quot; &quot;);
            }
        }
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/26/68/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/26/68/" itemprop="url">PAT B1010</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-26T11:38:59+00:00">
                2017-01-26
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <pre><code>#include &quot;stdio.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
int main(){
    int a[1010] = {0};
    int k, e, count = 0;//k为系数，e为指数，count计数不为零的导数项个数
    while (scanf(&quot;%d%d&quot;, &amp;k, &amp;e) != EOF) {
        a[e] = k;
    }
    a[0] = 0;
    for (int i = 1; i &lt;= 1000; i++) {
        a[i - 1] = a[i] * i; //求导公式
        a[i] = 0;
        if (a[i -1] != 0) {
            count ++;
        }
    }
    if (count == 0) {
        printf(&quot;0 0&quot;);//特例
    }else{
        for (int i = 1000; i &gt;= 0; i--) {
            if (a[i] != 0) {
                printf(&quot;%d %d&quot;, a[i], i);
                count--;
                if(count !=0) printf(&quot; &quot;);
            }
        }
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/26/67/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/26/67/" itemprop="url">PAT A1065</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-26T10:00:20+00:00">
                2017-01-26
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Given three integers A, B and C in [-2^63, 2^63], you are supposed to tell whether A+B &gt; C.</p>
<p>Input Specification:</p>
<p>The first line of the input gives the positive number of test cases, T (&lt;=10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.</p>
<p>Output Specification:</p>
<p>For each test case, output in one line “Case #X: true” if A+B&gt;C, or “Case #X: false” otherwise, where X is the case number (starting from 1).</p>
<p>Sample Input:<br>3<br>1 2 3<br>2 3 4<br>9223372036854775807 -9223372036854775808 0<br>Sample Output:<br>Case #1: false<br>Case #2: true<br>Case #3: false</p>
<pre><code>#include &quot;stdio.h&quot;
//#include &quot;algorithm&quot;
//using namespace std;
int main(){
    int t, tcase = 1;
    scanf(&quot;%d&quot;, &amp;t);
    while (t--) {
        long long a,b,c;
        scanf(&quot;%lld%lld%lld&quot;, &amp;a, &amp;b, &amp;c);
        long long res = a + b;
        bool flag;
        if (a &gt; 0 &amp;&amp; b &gt; 0 &amp;&amp; res &lt; 0) {
            flag = true;
        }else if (a &lt; 0 &amp;&amp; b &lt; 0 &amp;&amp; res &gt;= 0){
            flag = false;
        }else if (res &gt; c){
            flag = true;
        }else{
            flag = false;
        }
        if (flag) {
            printf(&quot;Case #%d: true\n&quot;, tcase++);
        }else{
            printf(&quot;Case #%d: false\n&quot;, tcase++);
        }
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/24/64/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/24/64/" itemprop="url">PAT A1042</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-24T01:40:00+00:00">
                2017-01-24
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.</p>
<p>Input Specification:</p>
<p>Each input file contains one test case. For each case, the first line contains an integer N (in [3, 105]), followed by N integer distances D1 D2 … DN, where Di is the distance between the i-th and the (i+1)-st exits, and DN is between the N-th and the 1st exits. All the numbers in a line are separated by a space. The second line gives a positive integer M (&lt;=104), with M lines follow, each contains a pair of exit numbers, provided that the exits are numbered from 1 to N. It is guaranteed that the total round trip distance is no more than 107.</p>
<p>Output Specification:</p>
<p>For each test case, print your results in M lines, each contains the shortest distance between the corresponding given pair of exits.</p>
<p>Sample Input:<br>5 1 2 4 14 9<br>3<br>1 3<br>2 5<br>4 1<br>Sample Output:<br>3<br>10<br>7</p>
<pre><code>#include &quot;stdio.h&quot;
int main(){
    int arr[100001],ans[100001];
    int n,m;
    int left,right;
    int x,y;
    scanf(&quot;%d&quot;,&amp;n);
    for (int i = 0; i &lt; n; i++) {
        scanf(&quot;%d&quot;,&amp;arr[i]);//读入数组
    }
    scanf(&quot;%d&quot;,&amp;m);
    for (int j = 0; j &lt; m; j++) {
        left = right = 0;//初始化
        scanf(&quot;%d %d&quot;, &amp;x, &amp;y);
        for (int i = ((x - 1 + n) % n);;) {//顺时针
            right += arr[i];
            i = ((i + 1 + n) % n);
            if (i == ((y - 1 + n) % n)) {
                break;
            }
        }
        for (int i = ((x - 2 + n) % n);;) {//逆时针
            left += arr[i];
            i = ((i - 1 + n) % n);
            if (i == ((y - 2 + n) % n)) {
            break;
            }
        }
        ans[j] = (left &gt; right)?right:left;
    }
    for (int j = 0; j &lt; m; j++) {
        printf(&quot;%d\n&quot;, ans[j]);
    }
    return 0;
}
</code></pre><p>这部分代码时间超时了，所以需要预处理一下。</p>
<pre><code>#include &quot;stdio.h&quot;
#include &quot;algorithm&quot;
using namespace std;
int dis[100001],A[100001];
int main(){
    int sum = 0, query, n, left, right;
    scanf(&quot;%d&quot;,&amp;n);
    for (int i = 1; i &lt;= n; i++) {
        scanf(&quot;%d&quot;, &amp;A[i]);
        sum += A[i];
        dis[i] = sum;
    }
    scanf(&quot;%d&quot;, &amp;query);
    for (int i = 0; i &lt; query; i++) {
        scanf(&quot;%d%d&quot;, &amp;left, &amp;right);
        if (left &gt; right) {
            swap(left, right);
        }
        int temp = dis[right - 1] - dis[left - 1];
        printf(&quot;%d\n&quot;, min(temp, sum - temp));
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/22/63/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/22/63/" itemprop="url">PAT A1042</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-22T22:56:00+00:00">
                2017-01-22
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Shuffling is a procedure used to randomize a deck of playing cards. Because standard shuffling techniques are seen as weak, and in order to avoid “inside jobs” where employees collaborate with gamblers by performing inadequate shuffles, many casinos employ automatic shuffling machines. Your task is to simulate a shuffling machine.</p>
<p>The machine shuffles a deck of 54 cards according to a given random order and repeats for a given number of times. It is assumed that the initial status of a card deck is in the following order:</p>
<p>S1, S2, …, S13, H1, H2, …, H13, C1, C2, …, C13, D1, D2, …, D13, J1, J2</p>
<p>where “S” stands for “Spade”, “H” for “Heart”, “C” for “Club”, “D” for “Diamond”, and “J” for “Joker”. A given order is a permutation of distinct integers in [1, 54]. If the number at the i-th position is j, it means to move the card from position i to position j. For example, suppose we only have 5 cards: S3, H5, C1, D13 and J2. Given a shuffling order {4, 2, 5, 3, 1}, the result will be: J2, H5, D13, S3, C1. If we are to repeat the shuffling again, the result will be: C1, H5, S3, J2, D13.</p>
<p>Input Specification:</p>
<p>Each input file contains one test case. For each case, the first line contains a positive integer K (&lt;= 20) which is the number of repeat times. Then the next line contains the given order. All the numbers in a line are separated by a space.</p>
<p>Output Specification:</p>
<p>For each test case, print the shuffling results in one line. All the cards are separated by a space, and there must be no extra space at the end of the line.</p>
<p>Sample Input:<br>2<br>36 52 37 38 3 39 40 53 54 41 11 12 13 42 43 44 2 4 23 24 25 26 27 6 7 8 48 49 50 51 9 10 14 15 16 5 17 18 19 1 20 21 22 28 29 30 31 32 33 34 35 45 46 47<br>Sample Output:<br>S7 C11 C10 C12 S1 H7 H8 H9 D8 D9 S11 S12 S13 D10 D11 D12 S3 S4 S6 S10 H1 H2 C13 D2 D3 D4 H6 H3 D13 J1 J2 C1 C2 C3 C4 D1 S5 H5 H11 H12 C6 C7 C8 C9 S2 S8 S9 H10 D5 D6 D7 H4 H13 C5</p>
<pre><code>#include &quot;stdio.h&quot;
#include &quot;stdlib.h&quot;
char map[5] = {&apos;S&apos;, &apos;H&apos;, &apos;C&apos;, &apos;D&apos;, &apos;J&apos;};
int main(){
    int start[55] = {0},end[55] = {0},list[55];//第0个不使用
    int n;
    scanf(&quot;%d&quot;,&amp;n);
    for (int a = 1; a &lt;= 54; a++) {
        start[a] = a;//初始化start数组
    }
    for (int a = 1; a &lt;= 54; a++) {
        scanf(&quot;%d&quot;, &amp;list[a]);
    }
    while (n--) {
        for (int a = 1; a &lt;= 54; a++) {
            end[list[a]] = start[a];
        }
        for (int a = 1; a &lt;= 54; a++) {
            start[a] = end[a];//把end数组复制到start数组
        }
    }
    for (int a = 1; a &lt;= 54; a++) {
        printf(&quot;%c%d&quot;,map[(start[a]-1)/13],(start[a]-1)%13+1);
        if(a &lt;54)printf(&quot; &quot;);
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/18/58/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/18/58/" itemprop="url">PAT B1018</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-18T23:58:00+00:00">
                2017-01-18
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>大家应该都会玩“锤子剪刀布”的游戏：两人同时给出手势，胜负规则如图所示：</p>
<p>现给出两人的交锋记录，请统计双方的胜、平、负次数，并且给出双方分别出什么手势的胜算最大。<br>输入格式：</p>
<p>输入第1行给出正整数N（&lt;=105），即双方交锋的次数。随后N行，每行给出一次交锋的信息，即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”，第1个字母代表甲方，第2个代表乙方，中间有1个空格。</p>
<p>输出格式：</p>
<p>输出第1、2行分别给出甲、乙的胜、平、负次数，数字间以1个空格分隔。第3行给出两个字母，分别代表甲、乙获胜次数最多的手势，中间有1个空格。如果解不唯一，则输出按字母序最小的解。</p>
<p>输入样例：<br>10<br>C J<br>J B<br>C B<br>B B<br>B C<br>C C<br>C B<br>J B<br>B C<br>J J<br>输出样例：<br>5 3 2<br>2 3 5<br>B B</p>
<pre><code>#include &quot;stdio.h&quot;
#include &quot;stdlib.h&quot;//引入exit
int change(char c){//将锤头剪刀布转化为数字判断胜负
    switch(c){
        case &apos;B&apos;: return 0;break;
        case &apos;C&apos;: return 1;break;
        case &apos;J&apos;: return 2;break;
        default: exit(-1);break;//输入不符合规范 退出
    }
}
int main(){
    int n;
    char alpha[3] = {&apos;B&apos;,&apos;C&apos;,&apos;J&apos;};
    int ansA[3] = {0},ansB[3] = {0};
    int countA[3] = {0},countB[3] = {0};
    char tempA, tempB;
    int A,B;
    scanf(&quot;%d&quot;, &amp;n);
    for(int i = 0; i &lt; n; i++){
        getchar();
        scanf(&quot;%c %c&quot;, &amp;tempA, &amp;tempB);
        A = change(tempA);
        B = change(tempB);
        if(A == B){//平局
            ansA[1]++;
            ansB[1]++;
        }else if( (A + 1) % 3 == B ){//A胜利
            ansA[0]++;
            ansB[2]++;
            countA[A]++;

        }else{//B胜利
            ansA[2]++;
            ansB[0]++;
            countB[B]++;
        }
    }
    int idA =0, idB = 0;
    printf(&quot;%d %d %d\n&quot;, ansA[0], ansA[1], ansA[2]);
    printf(&quot;%d %d %d\n&quot;, ansB[0], ansB[1], ansB[2]);
    for (int i = 0; i &lt; 3; i++) {
        if (countA[i] &gt; countA[idA]) idA = i;
        if (countB[i] &gt; countB[idB]) idB = i;
    }
    printf(&quot;%c %c\n&quot;, alpha[idA], alpha[idB]);
    return 0;
}
</code></pre><p>收获：<br>一定要注意如果解不唯一，则输出按字母序最小的解，所以字母表的顺序要按B C J；<br>并且布、锤头、剪刀 前一个克制后一个，可以转化为数字0 1 2，用循环数取余来判断胜负；</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://www.hemisu.com/2017/01/17/56/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="何米酥">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="何米酥`s Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/01/17/56/" itemprop="url">PAT B1012</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-17T16:57:00+00:00">
                2017-01-17
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/algorithm-PAT/" itemprop="url" rel="index">
                    <span itemprop="name">algorithm - PAT</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>给定一系列正整数，请按要求对数字进行分类，并输出以下5个数字：</p>
<ul>
<li>A1 = 能被5整除的数字中所有偶数的和； </li>
<li>A2 = 将被5除后余1的数字按给出顺序进行交错求和，即计算n1-n2+n3-n4…；</li>
<li>A3 = 被5除后余2的数字的个数；</li>
<li>A4 = 被5除后余3的数字的平均数，精确到小数点后1位；</li>
<li>A5 = 被5除后余4的数字中最大数字。</li>
</ul>
<p>输入格式：</p>
<p>每个输入包含1个测试用例。每个测试用例先给出一个不超过1000的正整数N，随后给出N个不超过1000的待分类的正整数。数字间以空格分隔。</p>
<p>输出格式：</p>
<p>对给定的N个正整数，按题目要求计算A1~A5并在一行中顺序输出。数字间以空格分隔，但行末不得有多余空格。</p>
<p>若其中某一类数字不存在，则在相应位置输出“N”。</p>
<p>输入样例1：<br>13 1 2 3 4 5 6 7 8 9 10 20 16 18<br>输出样例1：<br>30 11 2 9.7 9<br>输入样例2：<br>8 1 2 4 5 6 7 9 16<br>输出样例2：<br>N 11 2 N 9</p>
<pre><code>#include &lt;stdio.h&gt;
int main() {
    int count[5] = {0};
    int ans[5] = {0};
    int n, temp;
    scanf(&quot;%d&quot;, &amp;n);
    for (int i = 0; i &lt; n; i++) {
        scanf(&quot;%d&quot;, &amp;temp);//读入数字
        switch (temp % 5) {
            case 0:
                if (temp % 2 == 0) {
                    ans[0] += temp;
                    count[0]++;
                }
                break;
            case 1:
                if (count[1] %2 ==0) {
                    ans[1] += temp;
                }else{
                    ans[1] -= temp;
                }
                count[1]++;
                break;
            case 2:
                count[2]++;
                break;
            case 3:
                ans[3] += temp;
                count[3]++;
                break;
            case 4:
                if(temp&gt; ans[4]){
                    ans[4] = temp;
                    count[4]++;
                }
                break;
            default:
                break;
        }//switch
    }
    if (count[0]) {
        printf(&quot;%d &quot;,ans[0]);
    }else{
        printf(&quot;N &quot;);
    }
    if (count[1]) {
        printf(&quot;%d &quot;,ans[1]);
    }else{
        printf(&quot;N &quot;);
    }
    if (count[2]) {
        printf(&quot;%d &quot;,count[2]);
    }else{
        printf(&quot;N &quot;);
    }
    if (count[3]) {
        printf(&quot;%.1f &quot;,(double)ans[3]/count[3]);
    }else{
        printf(&quot;N &quot;);
    }
    if (count[4]) {
        printf(&quot;%d&quot;,ans[4]);
    }else{
        printf(&quot;N&quot;);
    }
    return 0;
}
</code></pre>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/17/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/17/">17</a><span class="page-number current">18</span><a class="page-number" href="/page/19/">19</a><span class="space">&hellip;</span><a class="page-number" href="/page/21/">21</a><a class="extend next" rel="next" href="/page/19/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="何米酥">
            
              <p class="site-author-name" itemprop="name">何米酥</p>
              <p class="site-description motion-element" itemprop="description">Just do...</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">202</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">78</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/hemisu" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/hemisu" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-globe"></i>知乎</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">何米酥</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
